import { MonitorTabManager, EdgeTabManager, GroupManager, SettingsTabManager } from './TabManager'

// Tab类型定义
export const TAB_TYPES = {
    MONITOR: 'monitor',
    GROUP: 'group',
    EDGE: 'edge'
}

// 分组类型定义
export const GROUP_TYPES = {
    PORT: 'port',
    DEVICE: 'device',
    VARIABLE: 'variable'
}

/**
 * 统一Tab管理器
 */
class TabManager {
    constructor() {
        this.monitor = new MonitorTabManager()
        this.group = new GroupManager()
        this.edge = new EdgeTabManager()
        this.settingsTabManager = new SettingsTabManager()
    }

    /**
     * 根据tab类型获取对应的API管理器
     * @param {string} tabType - tab类型
     * @returns {object} API管理器
     */
    getTabAPI(tabType) {
        switch (tabType) {
            case TAB_TYPES.MONITOR:
                return this.monitor
            case TAB_TYPES.GROUP:
                return this.group
            case TAB_TYPES.EDGE:
                return this.edge
            default:
                throw new Error(`不支持的tab类型: ${tabType}`)
        }
    }

    /**
     * 通用CRUD操作
     * @param {string} tabType - tab类型
     * @param {string} groupType - 分组类型
     * @param {string} operation - 操作类型
     * @param {any} params - 参数
     */
    async crud(tabType, groupType, operation, params = {}) {
        const tabAPI = this.getTabAPI(tabType)
        
        switch (operation) {
            case 'list':
                return await tabAPI[groupType].getList(params)
            case 'get':
                return await tabAPI[groupType].getById(params.id)
            case 'create':
                return await tabAPI[groupType].create(params.data)
            case 'update':
                return await tabAPI[groupType].update(params.id, params.data)
            case 'delete':
                return await tabAPI[groupType].delete(params.id)
            case 'batchDelete':
                return await tabAPI[groupType].batchDelete(params.ids)
            default:
                throw new Error(`不支持的操作: ${operation}`)
        }
    }
}

export default new TabManager() 